package com.OrderingServer.config;

import org.jasypt.encryption.StringEncryptor;
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Jasypt加密配置类
 * 用于配置Jasypt加密器，定义加密算法、密钥等参数
 */
@Configuration
public class JasyptConfig {

    @Value("${jasypt.encryptor.password}")
    String encryptorPassword;

    @Bean("jasyptStringEncryptor")
    public StringEncryptor stringEncryptor() {
        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        SimpleStringPBEConfig config = new SimpleStringPBEConfig();
        // 对于没有JCE的环境，使用较低强度的算法
        config.setAlgorithm("PBEWithMD5AndDES");
        config.setPassword(encryptorPassword); // 加密密钥
        config.setPoolSize("10");
        encryptor.setConfig(config);
        return encryptor;
    }
}
